package lev01_beginnerClass.class07_linkedLIst;

public class L03_QueueWithLinkedList {
    public static class Node<V> {
        public V value;
        public Node<V> next;

        public Node(V v) {
            value = v;
            next = null;
        }
    }

    public class MyQueue<V>{
        Node<V> head;
        Node<V> tail;
        int size;

        //构造器
        public  MyQueue(){
            head = null;
            tail = null;
            size = 0;
        }

        //判断是否为空
        public boolean isEmpty(){
            return  size == 0;
        }

        //获取大小
        public int getSize(){
            return size;
        }

        //添加元素
        public void offer(V value){
            Node cur = new Node(value);
            if(tail == null){
                head =tail = cur;
            }else {
                tail.next = cur;
                tail = cur;
            }
        }

        //删除节点
        public V poll(){
            V ans = null;
            if(head == null){
                head = tail = null;
            }else {
                ans = head.value;
                head = head.next;
                size--;
            }
            return  ans;
        }

        //获取值但是不删除节点（获取对列头节点）
        public V peek(){
            V ans = null;
            if(head == null){
                return ans;
            }else return head.value;
        }



    }
}
